package com.linkage.event.utils;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.linkage.event.feign.usercenter.entity.UserMgInfoVO;
import com.linkage.event.pojo.vo.UserLocationVo;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Map;

/**
 * 用户服务调用工具类
 */
@Slf4j
public class UserInterfUtils {

    private static String url="https://jbld.tiandao.fun:11001/exter";
//    private static String url="http://localhost:11001/exter";

    public static List<UserLocationVo> getUserListByDptCode(String dptCode, String  token){
        Map buss = MapUtil.builder().put("paramVar", dptCode).build();
        Map base = MapUtil.builder().put("usertoken", token).build();
        Map param = MapUtil.builder().put("buss", buss).put("base", base).build();
        HttpResponse response = HttpUtil.createPost(url+"/manage/getDptUserInfo").body(JSON.toJSONString(param), "application/json").execute();
        log.info("调用查询部门接口返参：" + response.body());
        List<UserLocationVo> dpt = null;
        if(StrUtil.isNotEmpty(response.body())){
            Map map = JSONObject.parseObject(response.body(), Map.class);
            dpt = JSONObject.parseArray(String.valueOf(map.get("buss")), UserLocationVo.class);
        }
        return dpt;
    }

    public static UserLocationVo getUserInfo(String mobile, String  token){
        Map buss = MapUtil.builder().put("paramVar", mobile).build();
        Map base = MapUtil.builder().put("usertoken", token).build();
        Map param = MapUtil.builder().put("buss", buss).put("base", base).build();
        HttpResponse response = HttpUtil.createPost(url+"/manage/getUserMgInfoVO").body(JSON.toJSONString(param), "application/json").execute();
        log.info("调用查询用户接口返参：" + response.body());
        Map map = JSONObject.parseObject(response.body(), Map.class);
        UserLocationVo user = JSONObject.parseObject(map.get("buss").toString(),UserLocationVo.class);
        log.info("获取到用户信息为" + user);
        return user;
    }
    public static List<UserLocationVo> getMgInfoByDptCode(String dptCode, String  token){
        Map buss = MapUtil.builder().put("dptCode", dptCode).build();
        Map base = MapUtil.builder().put("usertoken", token).build();
        Map param = MapUtil.builder().put("buss", buss).put("base", base).build();
        HttpResponse response = HttpUtil.createPost(url+"/manage/queryMgInfoByDptCode").body(JSON.toJSONString(param), "application/json").execute();
        log.info("调用查询部门接口返参：" + response.body());
        List<UserLocationVo> dpt = null;
        if(StrUtil.isNotEmpty(response.body())){
            Map map = JSONObject.parseObject(response.body(), Map.class);
            dpt = JSONObject.parseArray(String.valueOf(map.get("buss")), UserLocationVo.class);
        }
        return dpt;
    }

    public static List<UserMgInfoVO> getUserListLocations(String dptCode, String  token){
        Map buss = MapUtil.builder().put("paramVar", dptCode).build();
        Map base = MapUtil.builder().put("usertoken", token).build();
        Map param = MapUtil.builder().put("buss", buss).put("base", base).build();
        HttpResponse response = HttpUtil.createPost(url+"/manage/getLocationUsers").body(JSON.toJSONString(param), "application/json").execute();
        log.info("调用查询部门接口返参：" + response.body());
        List<UserMgInfoVO> dpt = null;
        if(StrUtil.isNotEmpty(response.body())){
            Map map = JSONObject.parseObject(response.body(), Map.class);
            dpt = JSONObject.parseArray(String.valueOf(map.get("buss")), UserMgInfoVO.class);
        }
        return dpt;
    }
}
